package com.springboot.ding.monitor.message;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.springboot.ding.monitor.BaseMessageInte;

import java.util.List;

/**
 * @description:
 * @author: zyj
 * @create: 2020-07-23 17:20
 **/

public class TextMessage extends BaseMessages implements BaseMessageInte {
    private static final long serialVersionUID = 1L;

    private String msgtype = "text";
    private List<String> phones; //通知哪些人
    private List<String> content; //通知内容

    public TextMessage(){}

    public TextMessage(List<String> phones, List<String> content, boolean isAtAll){
        this.phones = phones;
        this.content = content;
        this.isAtAll = isAtAll;
    }

    @Override
    public String coverMessage() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("msgtype", msgtype);

        JSONObject jsonContent = new JSONObject();
        StringBuffer sb = new StringBuffer();
        for(String contentStr: content){
            sb.append(contentStr+"\n");
        }
        jsonContent.put("content", sb.toString());
        jsonObject.put("text", jsonContent);

        JSONObject jsonUser = new JSONObject();
        jsonUser.put("atMobiles", phones);
        jsonUser.put("isAtAll", isAtAll);
        jsonObject.put("at", jsonUser);

//        this.accessToken = accessToken ;
//        this.timestamp = timestamp;
//        this.sign = sign;

       return JSON.toJSONString(jsonObject);
    }


    public String getMsgtype() {
        return msgtype;
    }

    public void setMsgtype(String msgtype) {
        this.msgtype = msgtype;
    }

    public List<String> getPhones() {
        return phones;
    }

    public void setPhones(List<String> phones) {
        this.phones = phones;
    }

    public List<String> getContent() {
        return content;
    }

    public void setContent(List<String> content) {
        this.content = content;
    }



}
